#ifndef _KBDRV_H_
#define _KBDRV_H_

#include "const.h"

#define KBSTATE_NORMAL          0
#define KBSTATE_SHIFT           1
#define KBSTATE_CTRL            2
#define KBSTATE_ALT             3
#define KBSTATE_NUMLOCK         4
#define KBSTATE_CAPSLOCK        5
#define KBSTATE_SHIFTCAPS       6
#define KBSTATE_SHIFTNUM        7
#define KBSTATE_ALTGR           8

#define MAX_KBSTATES            9
#define MAX_SCANCODES           0x80
#define MAX_KEYTABLES           16

struct keytable
{
  char *name;
  unsigned short normal[MAX_SCANCODES][MAX_KBSTATES];
  unsigned short extended[MAX_SCANCODES][MAX_KBSTATES];
};

class CKeyboardDriver
{
public:
	CKeyboardDriver();
	// Initialize keyboard driver
	u32 InitializeDriver();
	// Interrrupt handler
	void irq_handler(u16 irq);

	void init_keyboard(int reset);
	int getch(unsigned int timeout);
	int kbhit();
	void reboot();
	int reset_keyboard();


protected:
	void kbd_wait();
	int kbd_read_data();
	int kbd_wait_for_data();
	void kbd_write_data(unsigned char data);
	void kbd_write_command(unsigned char cmd);
	void setleds();
	void insert_key(unsigned char ch);
	void process_scancode(unsigned int scancode);


private:
	struct keytable *keytables[3];
	int keymap;

	unsigned char led_status;
	unsigned char control_keys;
	int ctrl_alt_del_enabled;
	int ext;


	unsigned char * keyboard_buffer;
	int keyboard_buffer_in;
	int keyboard_buffer_out;
};

#endif

